package leetcode.leetcode_3025;

import java.util.Arrays;

class Solution {
    public int numberOfPairs(int[][] points) {
        Arrays.sort(points,(a,b)->a[0]==b[0]?a[1]-b[1]: a[0]-b[0]);
        int ans =0 ;
        int n = points.length;
        for (int i = 0 ;i<n;i++){
            int yMax = Integer.MIN_VALUE;
            for (int j = i+1 ;j<n;j++){
                if (points[i][1]>= points[j][1]&&points[j][1]>yMax){
                    ans++;
                    yMax = points[j][1];
                }
            }
        }
        return ans;
    }
}